function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var e = t(require("../../../utils/filter")), a = t(require("../../../api/api")), u = (t(require("../../../utils/util")), 
require("../../../data/translate.js")), o = getApp();

Page({
    data: {
        amountLimit: !1,
        amountTypeLimit: !1,
        voucherShow: !1,
        isNoUse: !1,
        itc_to_cny: 0,
        selected_coupon_usd: 0,
        availITCOptions: u.ITC_AVAIL_OPTIONS
    },
    onShow: function() {
        o.globalData.selectedCoupon ? this.useCouponOperate(o.globalData.selectedCoupon) : this.unUseCouponOperate();
    },
    onUnload: function() {
        o.globalData.selectedCoupon = "";
    },
    onLoad: function() {},
    switchUseCoupon: function(t) {
        wx.navigateTo({
            url: "/pages/wallet/couponlist/coupon?use_type=0&available=1&redeemed_coupon=true&itc=" + this.data.itc_usd_value
        });
    },
    useCouponOperate: function(t) {
        0 !== Object.keys(t).length && this.setData({
            voucherShow: !0,
            selected_coupon_cny: t.coupon_value_cny,
            selected_coupon_usd: t.coupon_value_usd
        });
        var e = this.data.itc_usd_value - 100 * this.data.selected_coupon_usd, a = e > 0 ? e : 0;
        this.checkPaymentAmount(a);
    },
    unUseCouponOperate: function() {
        this.setData({
            voucherShow: !1,
            selected_coupon_cny: "",
            selected_coupon_usd: ""
        }), this.checkPaymentAmount(this.data.itc_usd_value);
    },
    checkPaymentAmount: function(t) {
        var a = e.default.convertCurrencyToCNY(t, o.globalData.currencyDatum);
        this.setData({
            itc_to_cny: a
        });
    },
    selectAmount: function(t) {
        var a = t.currentTarget.dataset.value, u = e.default.convertCurrencyToCNY(a, o.globalData.currencyDatum);
        this.setData({
            itc_to_cny: u,
            itc_usd_value: a,
            refund_itc_usd: "",
            amountLimit: !1,
            amountTypeLimit: !1
        });
    },
    blurAmountInput: function(t) {
        var a = t.detail.value, u = /^[+-]?(\d){1,}0$/, n = {
            label: a,
            value: (100 * a).toFixed()
        }, c = e.default.convertCurrencyToCNY(n.value, o.globalData.currencyDatum);
        a < 10 ? this.setData({
            amountLimit: !0,
            amountTypeLimit: !1
        }) : this.setData({
            amountLimit: !1,
            amountTypeLimit: !u.test(a)
        }), this.setData({
            itc_usd: n,
            itc_to_cny: c,
            itc_usd_value: n.value
        });
    },
    purchaseCheckout: function(t) {
        var e = this.data.itc_usd_value - 100 * this.data.selected_coupon_usd, u = {
            webchat_type: 6,
            itc_usd: e > 0 ? e : 0,
            pay_type: "X"
        };
        a.default.wechatPurchase({
            method: "POST",
            data: u,
            success: function(t) {
                console.log(t);
                var e = t.data.data;
                wx.requestPayment({
                    timeStamp: e.timeStamp,
                    nonceStr: e.nonceStr,
                    package: e.package,
                    signType: "MD5",
                    paySign: e.paySign,
                    success: function(t) {
                        wx.redirectTo({
                            url: "../teacher/teacher"
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    }
});